package njupt.proxy;

import java.util.Collection;
import java.util.List;

import njupt.dao.UserDAO;
import njupt.daoimp.UserDAOimp;
import njupt.dbc.DatabaseConnnection;
import njupt.vo.User;
public class UserDAOProxy implements UserDAO {
	private DatabaseConnnection dbc =null;
	private UserDAO dao;
	public UserDAOProxy(){
		try{
			
		this.dbc=new DatabaseConnnection();
		
		}catch(Exception e){
			e.printStackTrace();
		}
		if(this.dbc.getConnection()==null){
			System.out.println("error collection!!");
		};
		this.dao=new UserDAOimp(this.dbc.getConnection());
		}
	public boolean checkusers(User user) throws Exception {
	   boolean flag=false;
	   System.out.println("到了此处");
	   try{
		   flag=this.dao.checkusers(user);
	   }catch(Exception e){
		   throw e;
	   }finally{
		this.dbc.close();
	}
	   System.out.println(flag);
	   return flag;
	}	   
	
	
	public int insertuser(User user) throws Exception{         //注册用户，添加进去
		int flag=0;
		try{
			flag=this.dao.insertuser(user);
		}catch(Exception e){
			throw e;
		}finally{
			this.dbc.close();
		}
		return flag;
	}
	public List<String[]> showuser(int currentpage,int pagesize) throws Exception {
		try{
			 
			if(this.dao.showuser(currentpage, pagesize)!=null){
				System.out.println("userDAOimp is not null");
			}
		}catch(Exception e){
			throw e;
		}
		System.out.println("userDao return");
		return this.dao.showuser( currentpage, pagesize);
	}
	public int counttotalpage() throws Exception {
		if(this.dao.counttotalpage()!=0){
			return this.dao.counttotalpage();
		}
		else return 0;
	}
	public int updateuserinfo(String realname, String phone, String address,
			String zipcode, String email, String userid) throws Exception {
		
		return this.dao.updateuserinfo(realname, phone, address, zipcode, email, userid);
	}
	/* Overriding methods
	 */
	public int checkuserexit(int userid) throws Exception {
	   try{
		if(this.dao.checkuserexit(userid)!=0){
		   return this.dao.checkuserexit(userid);
	    }
	   else { return 0 ;}
	 
	}catch(Exception e){
		e.printStackTrace();}
	finally{this.dbc.close();}
	return userid;
}
}